package cn.wen233.core.service.impl;

import cn.wen233.basic.model.NodeRecord;
import cn.wen233.core.mapper.NodeRecordMapper;
import cn.wen233.core.page.PageIn;
import cn.wen233.core.page.PageOut;
import cn.wen233.core.service.NodeRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wenjie
 * @date 2022-05-07 10:26
 */
@Service
@RequiredArgsConstructor
public class PersistenceNodeRecordServiceImpl implements NodeRecordService {

    @Resource
    private NodeRecordMapper nodeRecordMapper;

    @Override
    public PageOut<NodeRecord> findPage(PageIn pageIn) {
        int start = pageIn.getNumber() * pageIn.getSize();
        List<NodeRecord> content = nodeRecordMapper.selectAllNodeRecord(start, pageIn.getSize());
        int countSum = nodeRecordMapper.selectNodeRecordSumCount();
        return PageOut.of(content, countSum, pageIn.getSize(), pageIn.getNumber());
    }

    @Override
    public void insert(NodeRecord nodeRecord) {
        nodeRecordMapper.insertNodeRecord(nodeRecord);
    }
}
